﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>btable</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/css/btable.css" />
    <script src="/static/js/inout/jquery-1.8.2.min.js"></script>
    <style>
        .ticke{
            width: 100%;
            position: relative;
        }
        .ticke b{
            color: red;
        }
    </style>
</head>

<body style=" background-color: gainsboro;">
<div style="margin:0px; background-color: white; margin:0 10px;">
    <blockquote class="layui-elem-quote" style="height: 31px;">
        <button type="button" class="layui-btn layui-btn-small" id="add"><i class="fa fa-plus" aria-hidden="true"></i>添加</button>
        <form class="layui-form" style="float:right;" action="/admin/agent/seleclit" method="post">
            <div class="layui-form-item" style="margin:0;">
                <label class="layui-form-label">搜索</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" placeholder="输入标题" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" style="padding:0;">
                    <button lay-filter="search" class="layui-btn" lay-submit><i class="fa fa-search" aria-hidden="true"></i> 查询</button>
                </div>
            </div>
        </form>
    </blockquote>
    <div id="content" style="width: 100%;height: 533px;"></div>
</div>

<script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/js/',
        v: new Date().getTime()
    }).use(['btable', 'form'], function () {
        var btable = layui.btable(),
                $ = layui.jquery,
                layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
                layer = layui.layer,//获取当前窗口的layer对象;
                form = layui.form();

        btable.set({
            openWait: true,//开启等待框
            elem: '#content',
            url: '/admin/agent/seleclit', //数据源地址
            pageSize: 10,//页大小
            params: {
                t: new Date().getTime() //额外的请求参数
            },
            columns: [{ //配置数据列
                fieldName: '标题', //显示名称
                field: 'titile', //字段名
                sortable: true //是否显示排序
            },{
                fieldName: '创建时间',
                field: 'addTime',
                sortable: true
            },{
                fieldName: '修改时间',
                field: 'updateTime',
                sortable: true
            },{
                fieldName: '启用/禁用状态',
                field: 'status',
                format: function (id, obj) {
                    //id
                    //行数据对象
                    //返回值：格式化的纯文本或html文本
                }
            },{
                fieldName: '操作',
                field: 'id',
                format: function (val,obj) {
                    var po = '';
                    if(obj.enable==1){
                        po="关闭";
                    }else{
                        po="启用";
                    }
                    var html = '<input type="button" value="修改" id="edit" data-action="edit" data-id="'+val+'" data-name="'+obj.title+'" class="layui-btn layui-btn-mini" /><button data-id="'+val+'" data-bd="'+obj.enable+'" class="layui-btn layui-btn-normal layui-btn-mini ble" onclick="defa(this)">'+po+'</button>' +
                            '<input type="button" value="删除" data-action="del" data-id="'+val+'" class="layui-btn layui-btn-mini layui-btn-danger del" name="del" />';
                    return html;
                }
            }],
            even: true,//隔行变色
            field: 'id', //主键ID
            //skin: 'row',
            checkbox: false,//是否显示多选框
            paged: true, //是否显示分页
            singleSelect: false, //只允许选择一行，checkbox为true生效
            onSuccess: function ($elem) { //$elem当前窗口的jq对象
                $elem.children('tr').each(function () {
                    $(this).children('td:last-child').children('input').each(function () {
                        var $that = $(this);
                        var action = $that.data('action');
                        var id = $that.data('id');
                        var names = $that.data('name');
                        $that.on('click', function () {
                            switch (action) {
                                case 'edit':
                                    window.location.href="/admin/agent/edit?id="+id;
                                    break;
                                case 'del': //删除
                                    layer.confirm('确定要删除？', {
                                        btn: ['确定','取消'] //按钮
                                    },function(){
                                        var id = $that.attr('data-id');
                                        $.ajax({
                                            type:"post",
                                            dataType: "json",
                                            url: "/admin/agent/del",
                                            data:{
                                                id:id
                                            },
                                            success:function(res){
                                                if(res.status==0){
                                                    layer.msg(res.msg,{icon: 1});
                                                    setTimeout('location.href="/admin/agent/index"',1000);
                                                }else{
                                                    layer.msg(res.msg,{icon: 1});
                                                }
                                            }
                                        });
                                    }, function(){

                                    });
                                    break;
                            }
                        });
                    });
                });
            }
        });
        btable.render();
        //监听搜索表单的提交事件
        form.on('submit(search)', function (data) {
            btable.get(data.field);
            return false;
        });
        $(window).on('resize', function (e) {
            var $that = $(this);
            $('#content').height($that.height() - 92);
        }).resize();
    });
    layui.use(['layer'], function () {
        var $ = layui.jquery,
                layer = layui.layer;

        //移除当前的选项卡
        $('#remove').on('click', function () {
            var tab = parent.tab;

            tab.deleteTab(tab.getCurrentTabId());
        });

        //这个是点击之后才添加的。
        $('#add').on('click', function () {
            window.location.href="/admin/agent/addproble";
        });

    });
    function defa(_this) {
        var m = $(_this).attr("data-bd")==1?'您是否要关闭该信息?':'您是否要启用该信息?';
        layer.confirm(m,{
            btn: ['确定','取消'] //按钮
        }, function(){
            var id = $(_this).attr("data-id");
            $.ajax({
                type:"post",
                dataType: "json",
                url: "/admin/agent/jinyong",
                data:{
                    id:id
                },
                success:function(res){
                    if(res.status==0){
                        layer.msg(res.msg);
                        setTimeout('location.href="/admin/agent/index"',1000);
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
        }, function(){
        });
    }
</script>
</body>

</html>